//
//  MyViewController.m
//  Tee-Study
//
//  Created by DJtd on 16/9/21.
//  Copyright © 2016年 杨迎龙. All rights reserved.
//

#import "MyViewController.h"
#import "SetUpTableViewCell.h"

@interface MyViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end


@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //
    
    self.view.backgroundColor = [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1];
    //
    
    [self creatPage];
    [self creatTableView];
    
    
}


- (void)creatPage {
    //绿色背景
    UILabel *backLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight*3.5/10)];
    backLabel.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backLabel];
    
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth/2 - ScreenWidth/8, ScreenHeight*3.5/20 - ScreenWidth/8 - 10, ScreenWidth/4, ScreenWidth/4)];
    self.headImage.image = [UIImage imageNamed:@"head"];
    if (![self.dataSource[@"Data"][@"HeadUrl"] isEqual:[NSNull null]]) {
//                self.headImage.image = [UIImage imageNamed:@"head"];
//        [self.headImage sd_setImageWithURL:[NSURL URLWithString:self.dataSource[@"Data"][@"HeadUrl"]]];
    }
    [self.headImage.layer setCornerRadius:(ScreenWidth/8)];
    self.headImage.layer.masksToBounds = YES;
    self.headImage.layer.borderWidth = 3;
    self.headImage.layer.borderColor = [[UIColor whiteColor] CGColor];
    [self.view addSubview:self.headImage];
    
    //用户名
    self.nameLabel = [[CustomLabel alloc] initWithFrame:CGRectMake(0, ScreenHeight*3.5/20 - ScreenWidth/8 + ScreenWidth/4, ScreenWidth, ScreenHeight * 60/1334) _text:@"小幻" _font:18];
    self.nameLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:self.nameLabel];
    
    if (self.dataSource[@"Data"][@"Name"] != nil) {
        self.nameLabel.text = self.dataSource[@"Data"][@"Name"];
    }
    
}


- (void)outLogIn {
    
    //获取UserDefaults单例
//    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//    //移除UserDefaults中存储的用户信息
//    [userDefaults removeObjectForKey:@"account"];
//    [userDefaults removeObjectForKey:@"password"];
//    [userDefaults removeObjectForKey:@"token"];
//    [userDefaults synchronize];
//    [self dismissViewControllerAnimated:YES completion:^{
//        
//    }];
}


- (void)creatTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    
//    [self.tableView registerClass:[ClearTableViewCell class] forCellReuseIdentifier:@"ClearTableViewCell"];
//    [self.tableView registerClass:[SetUpTableViewCell class] forCellReuseIdentifier:@"SetUpTableViewCell"];
    
    [self.view addSubview:self.tableView];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SetUpTableViewCell *setUpCell = [self.tableView dequeueReusableCellWithIdentifier:@"SetUpTableViewCell"];

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * 60/480)];
    view.backgroundColor = [UIColor lightGrayColor];
    
    switch (indexPath.row) {
        case 0:
            setUpCell.label.text = @"播放记录";
            setUpCell.Img.image = [[UIImage imageNamed:@"d1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            break;
        case 1:
            setUpCell.label.text = @"阅读记录";
            setUpCell.Img.image = [[UIImage imageNamed:@"d2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            break;
        case 2:
            setUpCell.label.text = @"我的问题";
            setUpCell.Img.image = [[UIImage imageNamed:@"d3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            break;
        case 3:
            setUpCell.label.text = @"我的笔记";
            setUpCell.Img.image = [[UIImage imageNamed:@"d4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            break;
        case 4:
            [setUpCell addSubview:view];
        default:
            break;
    }
    
    return setUpCell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //  取消cell 的选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
     if (indexPath.row == 2) {
        
//        UpdataViewController *updataVC = [[UpdataViewController alloc] init];
//        [self.navigationController pushViewController:updataVC animated:YES];
        
    } else {
        
//        AboutUsViewController *aboutUsVC = [[AboutUsViewController alloc] init];
//        [self.navigationController pushViewController:aboutUsVC animated:YES];
        
    }
    
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ScreenWidth * 60/480;
}



//- (void)setDataSource:(NSMutableDictionary *)dataSource {
//    _dataSource = dataSource;
//    
//    
//}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
